package com.simple.datax.dao.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.datax.dao.IDataxEnterpriseChannelDAO;
import com.simple.datax.vo.DataxEnterpriseChannelIdVO;
import com.simple.datax.vo.DataxEnterpriseChannelVO;
import com.simple.datax.vo.EnterpriseChannelDetailVO;
import com.simple.util.common.StringUtil;
import com.simple.util.object.PageInfoBean;

@Repository("dataxEnterPriseChannelDAO")
public class DataxEnterPriseChannelDAOImpl extends BaseDAO implements
		IDataxEnterpriseChannelDAO {

	@Override
	public DataxEnterpriseChannelVO findById(DataxEnterpriseChannelIdVO id) {
		return (DataxEnterpriseChannelVO)super.get(DataxEnterpriseChannelVO.class,id);
	}

	@Override
	public void saveOrUpdate(DataxEnterpriseChannelVO dataxEnterpriseChannelVO) {
		super.saveOrUpdate(dataxEnterpriseChannelVO);

	}

	@Override
	public List<DataxEnterpriseChannelVO> findAll() {
		return super.query(DataxEnterpriseChannelVO.class);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<EnterpriseChannelDetailVO> findAllDetailByPage(String fcEntCode,String fcEntName,PageInfoBean pageInfoBean) {
		final Map<String, Object> paramMap = new LinkedHashMap<String,Object>();
        final StringBuffer sb = new StringBuffer(500);
        
        sb.append("select a.id.fcEntcode,a.id.fcServicecode,b.fcChannelDesc,b.fcCommunType,b.fcCommunParam, "); 
        sb.append(" c.fcChannelDesc,c.fcCommunType,c.fcCommunParam , a.fiFlag"); 
        sb.append(" from DataxEnterpriseChannelVO a,DataxSendChannelVO b,DataxReceiveChannelVO c where 1>0 " );
        sb.append(" and a.fiSysReceiveId=c.fiId and a.fiSysSendId=b.fiId " );
        if(!StringUtil.isNull(fcEntCode)){
            sb.append( " and a.id.fcEntcode = :fcEntCode" );
            paramMap.put("fcEntCode", fcEntCode);
        }
        sb.append(" order by a.id.fcEntcode desc" );
		return (List<EnterpriseChannelDetailVO>)super.queryListByPage("a.id.fcEntcode", sb.toString(), paramMap, pageInfoBean);
	}

	@Override
	public void delete(DataxEnterpriseChannelVO dataxEnterpriseChannelVO) {
		super.delete(dataxEnterpriseChannelVO);
	}
	
	@Override
	public void delete(final DataxEnterpriseChannelIdVO id){
		super.delete(DataxEnterpriseChannelVO.class,id);
	}

	@Override
	public void update(DataxEnterpriseChannelVO dataxEnterpriseChannelVO) {
		super.saveOrUpdate(dataxEnterpriseChannelVO);
	}

}
